package org.lyimg.com.imgapplication.presenter;

import android.util.Log;

import org.lyimg.com.imgapplication.RetrofitHelper.ImgLoader;
import org.lyimg.com.imgapplication.bean.ImgType;
import org.lyimg.com.imgapplication.view.ImainView;

import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * Created by liuyong on 2019/1/18.
 */

public class mainPresenter extends BasePresenter<ImainView> {

    ImgLoader mImgLoader = new ImgLoader();

    public mainPresenter() {
    }

    public void initData() {
        if (null != weakReference) {
            weakReference.get().showloading();
        }

        mImgLoader.getImgtype().subscribe(new Consumer<List<ImgType>>() {

            @Override
            public void accept(List<ImgType> imgTypes) throws Exception {
                if (null != weakReference) {
                    weakReference.get().dissloading();
                    weakReference.get().showData(imgTypes);
                }
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                Log.e("TAG", "error message:" + throwable.getMessage());
                if (null != weakReference) {
                    weakReference.get().dissloading();
                    weakReference.get().showError("请求失败");
                }
            }
        });
    }

}
